package linwen.wang.config;

import org.springframework.amqp.core.*;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author wlw
 * @date 2023/3/9 10:31 PM
 */
@Configuration
public class RabbitMqConfig {
    /**
     * Json转换器
     */
    @Bean
    public Jackson2JsonMessageConverter jsonMessageConverter()
    {
        return new Jackson2JsonMessageConverter();
    }

    @Bean("directExchange")
    public Exchange exchange(){
        return ExchangeBuilder.directExchange("directExchange").build();
    }

    @Bean("directQueue")
    public Queue queue(){
        return QueueBuilder
                .durable("directQueue")
                .build();
    }
    @Bean
    public Binding binding(@Qualifier("directExchange")Exchange exchange,
                            @Qualifier("directQueue") Queue queue){
        return BindingBuilder
                .bind(queue)
                .to(exchange)
                .with("directKey")
                .noargs();
    }
}
